package com.itheima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.model.common.constants.mededia.WemediaConstants;
import com.heima.model.common.dtos.NewsAuthDTO;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmNewsDTO;
import com.heima.model.common.dtos.WmNewsPageReqDTO;
import com.heima.model.common.mededia.pojo.WmNews;
import com.itheima.wemedia.service.WnNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "文章管理api",tags = "文章管理api")
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WnNewsService wnNewsService;
    @ApiOperation("分页带条件查询自媒体文章列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDTO wmNewsPageReqDTO){
       return  wnNewsService.findList(wmNewsPageReqDTO);
    }
    @ApiOperation("自媒体文章-发布、修改、保存草稿")
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDTO wmNewsDTO){
        return wnNewsService.submit(wmNewsDTO);

    }
    @ApiOperation("根据文章id查询")
    @GetMapping("/one/{id}")
    public ResponseResult selectByid(@PathVariable("id") Integer id){
        return wnNewsService.selectById(id);
    }
    @ApiOperation("根据id删除文章")
    @GetMapping("/del_news/{id}")
    public ResponseResult delNewsById(@PathVariable("id") Integer id){
        return wnNewsService.delNewsById(id);
    }
    @ApiOperation("文章上下架")
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDTO dto){
        return wnNewsService.downOrUp(dto);

    }
    @PostMapping("/list_vo")
    public ResponseResult findList(@RequestBody NewsAuthDTO dto) {
        return wnNewsService.selectList(dto);

    }
    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @ApiOperation(value = "查询自媒体文章详情",notes = "返回值带作者信息，主要运营管理端调用")
    @GetMapping("/one_vo/{id}")
    public ResponseResult findWmNewsVo(@PathVariable("id") Integer id) {
        return wnNewsService.findWmNewsVo(id);

    }
    /**
     * 文章审核成功
     * @param dto
     * @return
     */
    @ApiOperation("人工审核通过 状态:4")
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDTO dto) {
        return wnNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_PASS,dto);

    }

    /**
     * 文章审核失败
     * @param dto
     * @return
     */
    @ApiOperation("人工审核失败 状态:2")
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDTO dto) {
        return wnNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_FAIL,dto);
    }
    /**
     * 修改文章
     * @param wmNews
     * @return
     */
    @ApiOperation("根据id修改自媒体文章")
    @PutMapping("/update")
    public ResponseResult updateWmNews(@RequestBody WmNews wmNews) {
        wnNewsService.updateById(wmNews);
        return ResponseResult.okResult();
    }


}
